package com.iprojectmanager.views;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import com.iprojectmanager.managers.*;
import com.iprojectmanager.entities.*;

/**
 * @author Trejo Sandoval Sergio Alberto
 */
public class VistaAdministrador extends Vista
{

    //Metodo para la vista principal
    public void mainView(PrintWriter out,HttpServletRequest request)throws ServletException, IOException 
    {
        HttpSession user = request.getSession();
        Administrador root = (Administrador)user.getAttribute("user");
        
            out.println(Utilities.getDocType());
            out.println("<HTML>" + Utilities.getHead("Administrador del Sistema"));
            out.println("<div id=\"container\">");
            out.println(Utilities.getIntro("Administrador del Sistema",root));

            String form = 
                    "<div id=\"pageContent\">"+
                            "<div id=\"selection1\">" + this.getFormProyectos() + "</div>" +
                            "<div id=\"selection2\">" + this.getFormUsuarios() + "</div>"+
                            "<div id=\"selection3\">" + this.getFormRoles() + "</div>" +
                            Utilities.getFooter() + 
                    "</div>";

            out.println(form);
            out.println(Utilities.getMenu());
            out.println("</div> <!-- fin container---></BODY></HTML>");
            out.close();
    }

    //Metodo para la vista en caso de errores
    @Override
    public void operationResult(PrintWriter out)throws ServletException, IOException 
    {
    } 

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException 
    {
        PrintWriter out = response.getWriter();
            response.setContentType("text/html");
            mainView(out,request);
    }

    @Override
    public String getServletInfo() {
        return "Vista del Administrador";
    }
    
    public String getFormProyectos()
    {
        ProjectManager projects = new ProjectManager();
        String proyectos = "";
        for(Proyecto pro : projects.getProyectos())
        {
            //"<option>proy1</option>"+
            proyectos += "<option>" + pro.getNombre()+ "</option>";
        }

        return                          
                "<h3><span>Administracion de Proyectos</span></h3>"+
                "<p class=\"p1\"><span>"+
                    "<form action=\"ProjectControl\" method=\"GET\">"+
                        "<label>PROYECTOS:</label>"+
                        "<select name=\"proyectos\">"+ 
                            proyectos +
                        "</select><br></br>"+
                        "<label>ACCIONES:</label>"+
                            "<select name=\"operacionesproyectos\">"+
                                "<option value=\"crear\">Crear</option>"+
                                "<option value=\"eliminar\">Eliminar</option>"+
                                "<option value=\"modificar\">Modificar</option>"+
                                "<option value=\"listarproyecto\">Listar Proyectos</option>"+
                            "</select><br></br>"+
                         "<button type=\"submit\">Aceptar</button>"+
                    "</form>"+
                "</span></p>";
    }
    
    public String getFormUsuarios()
    {
        return
                "<h3><span>Administracion de Usuarios</span></h3>"+
                "<p class=\"p1\"><span>"+
                    "<form action=\"UsersControl\" method=\"GET\">"+
                        "<label>ACCIONES:</label>"+
                        "<select name=\"operacionesusuarios\">"+
                            "<option>Crear</option>"+
                            "<option>Modificar</option>"+
                            "<option>Eliminar</option>"+
                            "<option>Asignar Roles</option>"+
                        "</select><br></br>"+
                        "<button type=\"submit\">Aceptar</button>"+
                    "</form>"+
                "</span></p>";
    }
    
    public String getFormRoles()
    {
        return 
                "<h3><span>Administracion de Roles</span></h3>"+
                "<p class=\"p1\"><span>"+
                    "<form action=\"VistaOperacionRol\" method=\"GET\">"+
                        "<label>ACCIONES:</label>"+
                        "<select name=\"operacionesroles\">"+
                            "<option>Crear</option>"+
                            "<option>Eliminar</option>"+
                            "<option>Modificar</option>"+
                        "</select><br></br>"+
                        "<button type=\"submit\">Aceptar</button>"+
                    "</form>"+
                "</span></p>";
    }
}
